package com.xhs.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ZipUtil;
import com.xhs.dto.request.ZipFileRequest;
import com.xhs.message.Result;
import com.xhs.message.ReturnResult;
import com.xhs.service.ZipFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @desc:
 * @projectName: tools-parent
 * @author: xhs
 * @date: 2023/3/14 23:06
 * @version: JDK 1.8
 */
@Slf4j
@Service
public class ZipFileServiceImpl implements ZipFileService {

    /**
     * 压缩文件
     *
     * @param request
     * @return
     */
    @Override
    public ReturnResult<Object> zipFile(ZipFileRequest request) {
        log.info("zipPath:{}", request.getZipPath());
        log.info("newZipPath:{}", request.getNewZipPath());
        String path = request.getNewZipPath() + DateUtil.today() + ".zip";
        ZipUtil.zip(request.getZipPath(), path);
        return ReturnResult.build(Result.ZIP_FILE_SUCCESS).setData(path);
    }
}
